import { createRequire } from 'module'
import axios from 'axios';
const require = createRequire(import.meta.url)
import { resolve } from 'path'
const express = require('express')
const commonRouter = express.Router();

commonRouter.get("/getCurrentAddress", function (req, res) {
    res.writeHead(200, { "content-type": "text/html;charset=utf-8" })

    let longitude = "113.324520";
    let latitude = "23.099994";
    let baseUrl = 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=6p1lvvDcS7lcssFNZNeGVLlkn6FlFEOA&output=json&coordtype=wgs84ll&location='
    let requestUrl = `${baseUrl}${latitude},${longitude}`

    let returnValue = {};

    axios.get(requestUrl).then((res) => {
        returnValue = res.data;
        resolve();
    }).then(() => {
        res.end(JSON.stringify(returnValue));
    })
})
export const common = commonRouter;